/**
 * 01数组，7种操作
 * 1 区间设置
 * 2 区间异或
 * 3 区间1的数量
 * 4 区间最长连续1的数量
 * 5 区间0的数量
 * 6 区间最长连续0的数量
 * 7 区间段数
 */
#include <bits/stdc++.h>
using namespace std;

char *__abc147, *__xyz258, __ma369[1000000];
#define __hv007() ((__abc147==__xyz258) && (__xyz258=(__abc147=__ma369)+fread(__ma369,1,100000,stdin),__abc147==__xyz258) ? EOF : *__abc147++)

int getInt(){
	int sgn = 1;
	char ch = __hv007();
	while( ch != '-' && ( ch < '0' || ch > '9' ) ) ch = __hv007();
	if ( '-' == ch ) {sgn = 0;ch=__hv007();}
 
	int ret = (int)(ch-'0');
	while( '0' <= (ch=__hv007()) && ch <= '9' ) ret = ret * 10 + (int)(ch-'0');
	return sgn ? ret : -ret;
}



struct SegTree{ // 线段树带延迟

using llt = int;

int N;

struct _t{
    array<int, 2> longest; // 01最长的长度
    array<int, 2> left;    // 01左边长度
    array<int, 2> right;   // 01右边长度
    array<int, 2> count;   // 01数量
    int duan;              // 连续的段数 
    bool operator == (const _t & b) const {
        return longest == b.longest and left == b.left and right == b.right and count == b.count and duan == b.duan;
    }
};

using value_type = _t;
vector<value_type> data; // 线段树

using lazy_type = llt;
vector<lazy_type> lazy; // 延迟标记 按位操作, 210, 第2位表示异或，第1位表示设置，第0位表示设置的值

/// 从下往上计算信息，要变动
value_type _up_(const value_type & ls, const value_type & rs) {
    // assert(0);
    if(rs == value_zero()) return ls;
    if(ls == value_zero()) return rs;

    value_type ans;

    int leftn = ls.count[0] + ls.count[1]; // 左长度
    int rightn = rs.count[0] + rs.count[1]; // 右长度

    if(leftn == ls.right[0]){ // 左段全0
        assert(0 == ls.count[1] and 0 == ls.left[1] and 0 == ls.right[1] and 0 == ls.longest[1]);
        assert(leftn == ls.count[0] and leftn == ls.left[0] and leftn == ls.right[0] and leftn == ls.longest[0]);
        assert(1 == ls.duan);

        if(rightn == rs.left[0]){ // 右段全0
            ans = {
                {leftn + rightn, 0}, 
                {leftn + rightn, 0}, 
                {leftn + rightn, 0}, 
                {leftn + rightn, 0}, 
                1
            };
        }else if(rightn == rs.left[1]){
            ans = {
                {leftn, rightn}, 
                {leftn, 0}, 
                {0, rightn}, 
                {leftn, rightn}, 
                2
            };
        }else{
            int zero = leftn + rs.left[0];
            ans = {
                {max(zero, rs.longest[0]), rs.longest[1]}, 
                {zero, 0}, 
                rs.right, 
                {ls.count[0] + rs.count[0], rs.count[1]}, 
                zero == leftn ? rs.duan + 1 : rs.duan
            };
        }
    }else if(leftn == ls.right[1]){ // 左段全1
        assert(0 == ls.count[0] and 0 == ls.left[0] and 0 == ls.right[0] and 0 == ls.longest[0]);
        assert(leftn == ls.count[1] and leftn == ls.left[1] and leftn == ls.right[1] and leftn == ls.longest[1]);
        assert(1 == ls.duan);
    
        if(rightn == rs.left[0]){
            ans = {{rightn, leftn}, {0, leftn}, {rightn, 0}, {rightn, leftn}, 2};
        }else if(rightn == rs.left[1]){
            ans = {{0, leftn + rightn}, {0, leftn + rightn}, {0, leftn + rightn}, {0, leftn + rightn}, 1};
        }else{
            int one = leftn + rs.left[1];
            ans = {{rs.longest[0], max(one, rs.longest[1])}, {0, one}, rs.right, {rs.count[0], ls.count[1] + rs.count[1]}, one == leftn ? rs.duan + 1 : rs.duan};
        }
    }else{ // 左段都有
        assert(ls.count[0] and ls.count[1]);

        if(rightn == rs.left[0]){
            int zero = rightn + ls.right[0];
            ans = {{max(zero, ls.longest[0]), ls.longest[1]}, ls.left, {zero, 0}, {ls.count[0] + rs.count[0], ls.count[1]}, zero == rightn ? ls.duan + 1 : ls.duan};
        }else if(rightn == rs.left[1]){
            int one = rightn + ls.right[1];
            ans = {{ls.longest[0], max(ls.longest[1], one)}, ls.left, {0, one}, {ls.count[0], ls.count[1] + rs.count[1]}, one == rightn ? ls.duan + 1 : ls.duan};
        }else{
            int same0 = ls.right[0] and rs.left[0] ? 1 : 0;
            int same1 = ls.right[1] and rs.left[1] ? 1 : 0;
            assert(same0 + same1 < 2);
            ans = {{max(ls.longest[0], rs.longest[0]), max(ls.longest[1], rs.longest[1])}, ls.left, rs.right, {ls.count[0] + rs.count[0], ls.count[1] + rs.count[1]}, ls.duan + rs.duan - (same0 + same1)};
            if(same0) ans.longest[0] = max(ans.longest[0], ls.right[0] + rs.left[0]);
            else if(same1) ans.longest[1] = max(ans.longest[1], ls.right[1] + rs.left[1]);
        }
    }

    return ans;
}

/// 从上往下计算信息，要变动
void _dn_(int t, int s, int e, const lazy_type & delta) {
    // assert(0);
    int n = e - s + 1;
    auto & x = data[t];
    /// 先设置
    if(delta & 2){
        int v = delta & 1;
        x.longest[v] = x.left[v] = x.right[v] = x.count[v] = n;
        x.longest[v ^ 1] = x.left[v ^ 1] = x.right[v ^ 1] = x.count[v ^ 1] = 0;
        x.duan = 1;
    }
    /// 再异或
    if(delta & 4){
        swap(x.longest[0], x.longest[1]);
        swap(x.left[0], x.left[1]);
        swap(x.right[0], x.right[1]);
        swap(x.count[0], x.count[1]);
    }

    /// 如果有设置操作
    if(delta & 2){
        lazy[t] = delta;
    }else{
        if((lazy[t] >> 2) == (delta >> 2)) lazy[t] &= 3;
        else lazy[t] |= 4;
    }
    return;
}

/// 初始化，清零，不用动
void init(int n) {
    data.assign((N = n) + 1 << 2, value_zero());
    lazy.assign(n + 1 << 2, lazy_zero());
}

/// 这个函数不用动
void modify(int a, int b, const lazy_type & delta){
    _modify(1, 1, N, a, b, delta);
}

/// 这个函数不用动
value_type query(int a, int b){
    return _query(1, 1, N, a, b);
}

/// 这个函数不用动
void build(int n) {
    _build(1, 1, n);
}

/// 几乎不用动
value_type _query(int t, int s, int e, int a, int b) {
    if(a <= s and e <= b) {
        return data[t];
    }
    _pushDown(t, s, e);
    int mid = (s + e) >> 1;
    value_type ans = value_zero();
    if(a <= mid) ans = _up_(ans, _query(lson(t), s, mid, a, b));
    if(mid < b) ans = _up_(ans, _query(rson(t), mid + 1, e, a, b));
    return ans;
}

/// 几乎不用动
void _modify(int t, int s, int e, int a, int b, const lazy_type & delta) {
    if(a <= s and e <= b) {
        _dn_(t, s, e, delta);
        return;
    }
    _pushDown(t, s, e);
    int mid = (s + e) >> 1;
    if(a <= mid) _modify(lson(t), s, mid, a, b, delta);
    if(mid < b) _modify(rson(t), mid + 1, e, a, b, delta);
    _pushUp(t);
    return;
}

/// 这个函数不用动
void _pushUp(int t) {
    data[t] = _up_(data[lson(t)], data[rson(t)]);
}

/// 这个函数几乎不用动
void _pushDown(int t, int s, int e) {
    if(lazy_zero() == lazy[t]) return;
    auto & lz = lazy[t];
    auto ls = lson(t), rs = rson(t);
    int mid = (s + e) >> 1;

    _dn_(ls, s, mid, lz);
    _dn_(rs, mid + 1, e, lz);

    lz = lazy_zero();
}


/// 几乎不用动
void _build(int t, int s, int e) {
    if(s == e) {
        int x = s % 2;
        auto & d = data[t]; // 注意提供value_type的初始化
        d.longest[x] = d.left[x] = d.right[x] = d.count[x] = d.duan = 1;
        d.longest[x ^ 1] = d.left[x ^ 1] = d.right[x ^ 1] = d.count[x ^ 1] = 0;
        return; 
    }
    int mid = (s + e) >> 1;
    _build(lson(t), s, mid);
    _build(rson(t), mid + 1, e);
    _pushUp(t);
}

/// 辅助函数，视延迟的类型而变动
static const lazy_type & lazy_zero() {
    static const lazy_type LAZY0 = 0;
    return LAZY0; 
}

/// 辅助函数，视线段树信息类型而变动
static const value_type & value_zero() {
    static const value_type VALUE0 = {{0, 0}, {0, 0}, {0, 0}, {0, 0}, 0};
    return VALUE0;
}

/// 这两个函数不用变动
static int lson(int x) {return x << 1;}
static int rson(int x) {return lson(x) | 1;}


};

int N, M;
SegTree St;

int main(){
    // freopen("z.txt", "r", stdin);
    N = getInt(); M = getInt();
    St.init(N); St.build(N);
    for(int c,a,b,q=1;q<=M;++q){
        c = getInt(); a = getInt(); b = getInt();
        switch(c){
            case 1: St.modify(a, b, 2|getInt());break;
            case 2: St.modify(a, b, 4);break;
            case 3: printf("%d\n", St.query(a, b).count[1]);break;
            case 4: printf("%d\n", St.query(a, b).longest[1]);break;
            case 5: printf("%d\n", St.query(a, b).count[0]);break;
            case 6: printf("%d\n", St.query(a, b).longest[0]);break;
            case 7: printf("%d\n", St.query(a, b).duan);break;
            default: assert(0);
        }
    }
    return 0;
}